home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Dials.c *
- * *
- * Line Printer Daemon using TCP/IP printer protocol *
- * *
- * -------------- The dialog routines -------------- *
- * *
- * Written by Casper Boon, August, 1992. *
- * *
- * © 1992 Casper Boon. *
- * *
- ************************************************************************/
-
- #include "LPD.H"
- #include "CvtAddr.h"
- #include "lpdProtos.H"
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- integer doAbout()
- {
- DialogRecord DialStorg;
- DialogPtr aboutDial;
- WindowPtr aPort;
- integer ItemHit;
- Rect aRect, bRect;
-
- GetPort(&aPort);
- SetRect(&aRect, 10, -15, 15, -10);
- SetPort( aboutDial = GetNewDialog(AboutDLOG,
- (Ptr)&DialStorg, (WindowPtr) -1) );
- bRect = aboutDial->portRect;
- bRect.top -= 20;
- LocalToGlobal(&topLeft(bRect));
- LocalToGlobal(&botRight(bRect));
- ZoomRect(&aRect, &bRect, TRUE);
- ShowWindow(aboutDial);
-
- InstallUserItem(aboutDial, abtDefFrm, (ProcPtr)DefaultFrame);
-
- ItemHit = 0;
- while (ItemHit != okBtn)
- ModalDialog(NIL, &ItemHit);
-
- SetPort(aPort);
- CloseDialog(aboutDial);
- ZoomRect(&aRect, &bRect, FALSE);
-
- return ItemHit;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- Boolean ValidHost(LongWord hostID)
- {
- integer nHosts, i;
- LongWord *hst;
- Boolean res = FALSE;
- nHosts = GetHandleSize(hosts) / sizeof(LongWord);
-
- if (nHosts)
- {
- HLock(hosts);
- hst = (LongWord*)(*hosts);
- for (i = 0; i < nHosts; i++)
- {
- if (hostID == hst[i])
- {
- res = TRUE;
- break;
- }
- }
- HUnlock(hosts);
- }
- return res;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- Boolean ValidWindow(DialogPtr dial);
- Boolean ValidWindow(DialogPtr dial)
- {
- WindowPtr window;
-
- window = FrontWindow(); /* get the current front window */
-
- while (window != NIL)
- {
- if (window == dial)
- return TRUE;
- window = (WindowPtr)((WindowPeek)window)->nextWindow;
- }
- return FALSE;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- /* return FALSE if you want the main event loop to process this event */
- integer HandleDEvent(EventRecord *myEvent)
- {
- DialogPtr whichDial = 0;
- integer itemHit = 0;
- GrafPtr aPort;
-
-
- if (myEvent->what == updateEvt)
- {
- whichDial = (DialogPtr)myEvent->message;
- if (!ValidWindow(whichDial)) return TRUE;
- GetPort(&aPort);
- SetPort(whichDial);
- BeginUpdate(whichDial);
- DrawDialog(whichDial);
- EndUpdate(whichDial);
- SetPort(aPort);
- return FALSE;
- }
-
- DialogSelect(myEvent, &whichDial, &itemHit);
-
- if (!ValidWindow(whichDial)) return TRUE;
-
- if (((WindowPeek)whichDial)->windowKind < 0)
- return TRUE; /* a system window, we should never have got here */
-
- return TRUE;
- }
-
-
- /************************************************************************
- * *
- * Banner processing. Handles putting up the dialogues for processing, *
- * changing the messages and tearing the banners down again. *
- * *
- ************************************************************************/
- DialogPtr lpd_ban = NIL;
- DialogRecord lpd_rec;
- integer lpd_lst = 0;
- DialogPtr prt_ban = NIL;
- DialogRecord prt_rec;
- integer prt_scl = 0;
- integer prt_clk = 0;
-
- pascal void Clock(DialogPtr dial, integer item);
- pascal void Scaler(DialogPtr dial, integer item);
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void Banners_Down()
- {
- if (lpd_ban) CloseDialog(lpd_ban);
- lpd_ban = NIL;
- if (prt_ban) CloseDialog(prt_ban);
- prt_ban = NIL;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void Banners_Back()
- {
- if (lpd_lst) LPD_Banner_Up();
- if (prt_scl) PRT_Banner_Up("\p");
- if (prt_clk) PSTAT_Banner_Up("\p");
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- pascal void Scaler(DialogPtr dial, integer item)
- {
- Handle hand;
- integer type;
- Rect rect;
- LongInt pct = GetWRefCon(dial);
-
- SetPort(dial);
- GetDItem(dial, item, &type, &hand, &rect);
- FrameRect(&rect);
- InsetRect(&rect, 1, 1);
- rect.right = ( ( (rect.right - rect.left) * pct ) / 100 ) + rect.left;
- FillRect(&rect, gray);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- pascal void Clock(DialogPtr dial, integer item)
- {
- Handle hand;
- integer type;
- Rect rect;
- LongInt tick = Ticks % 360;
- LongInt pat = GetWRefCon(dial);
-
- SetPort(dial);
- GetDItem(dial, item, &type, &hand, &rect);
- PenSize(4, 4);
- FrameOval(&rect);
- InsetRect(&rect, 6, 6);
- EraseArc(&rect, tick, 90);
- FillArc(&rect, tick+ 90, 90, black);
- EraseArc(&rect, tick+180, 90);
- FillArc(&rect, tick+270, 90, black);
-
- PenNormal();
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void LPD_Banner_Up()
- {
- if (lpd_ban) return;
- lpd_lst = rcvFlDLOG;
-
- if (inBackground) return;
-
- lpd_ban = GetNewDialog(rcvFlDLOG, &lpd_rec, (WindowPtr) -1L);
-
- if (!lpd_ban) return;
-
- SetWRefCon(lpd_ban, 0);
- InstallUserItem(lpd_ban, barUsr, (ProcPtr)Scaler);
- DrawDialog(lpd_ban);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void LPD_Banner_Down()
- {
- if (lpd_ban)
- CloseDialog(lpd_ban);
- lpd_ban = NIL;
- lpd_lst = 0;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void LPD_Banner_PCent(LongInt done, LongInt want)
- {
- LongInt percent;
- if (!lpd_ban) return;
- if (want > 0) percent = (done * 100)/want;
- else percent = 100;
- SetWRefCon(lpd_ban, percent);
- Scaler(lpd_ban, barUsr);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void PRT_Banner_Up(StringPtr status)
- {
- if (prt_ban) return;
- prt_scl = prtFlDLOG;
-
- if (inBackground) return;
-
- prt_ban = GetNewDialog(prtFlDLOG, &prt_rec, (WindowPtr) -1L);
-
- if (!prt_ban) return;
-
- SetDialText(prt_ban, stusTxt, status);
- SetWRefCon(prt_ban, 0);
- InstallUserItem(prt_ban, barUsr, (ProcPtr)Scaler);
- DrawDialog(prt_ban);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void PRT_Banner_Down()
- {
- if (prt_ban)
- CloseDialog(prt_ban);
- prt_ban = NIL;
- prt_scl = 0;
- prt_clk = 0;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- Boolean NewMessage(integer which, StringPtr message);
- Boolean NewMessage(integer which, StringPtr message)
- {
- Str255 buffer;
- Byte *b, *m;
- Byte c;
- if (!message) return FALSE;
- GetDialText(prt_ban, which, buffer);
- b = buffer; m = message;
- c = *b + 1;
- while (c--)
- if (*b++ != *m++) return TRUE;
- return FALSE;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void PRT_Banner_PCent(LongInt done, LongInt want, StringPtr message)
- {
- LongInt percent;
- if (!prt_ban) return;
- if (want > 0) percent = (done * 100)/ want;
- else percent = 100;
- SetWRefCon(prt_ban, percent);
- if (NewMessage(stusTxt, message))
- SetDialText(prt_ban, stusTxt, message);
- Scaler(prt_ban, spinUsr);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void PSTAT_Banner_Up(StringPtr status)
- {
- if (prt_ban) return;
- prt_clk = pStatDLOG;
-
- if (inBackground) return;
- prt_ban = GetNewDialog(pStatDLOG, &prt_rec, (WindowPtr) -1L);
-
- if (!prt_ban) return;
-
- SetDialText(prt_ban, stusTxt, status);
- SetWRefCon(prt_ban, 0);
- InstallUserItem(prt_ban, spinUsr, (ProcPtr)Clock);
- DrawDialog(prt_ban);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void PSTAT_Banner_Step(StringPtr message)
- {
- if (!prt_ban) return;
- if (NewMessage(stusTxt, message))
- SetDialText(prt_ban, stusTxt, message);
- Clock(prt_ban, spinUsr);
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void POPEN_Banner_Up(StringPtr name, StringPtr status)
- {
- Str255 buf;
-
- if (prt_ban) return;
- prt_clk = pStatDLOG;
-
- if (inBackground) return;
- prt_ban = GetNewDialog(pStatDLOG, &prt_rec, (WindowPtr) -1L);
-
- if (!prt_ban) return;
-
- psprintf(buf, "Looking for Printer %p", name);
- SetDialText(prt_ban, whyText, buf);
- SetDialText(prt_ban, stusTxt, status);
- SetWRefCon(prt_ban, 0);
- InstallUserItem(prt_ban, spinUsr, (ProcPtr)Clock);
- DrawDialog(prt_ban);
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void CONFIG_Banner_Up()
- {
- if (prt_ban) return;
- prt_clk = pStatDLOG;
-
- if (inBackground) return;
- prt_ban = GetNewDialog(pStatDLOG, &prt_rec, (WindowPtr) -1L);
-
- if (!prt_ban) return;
-
- SetDialText(prt_ban, whyText, "\pReading Config File");
- SetDialText(prt_ban, stusTxt, "\p");
- SetWRefCon(prt_ban, 0);
- InstallUserItem(prt_ban, spinUsr, (ProcPtr)Clock);
- DrawDialog(prt_ban);
- }
-